{% extends "back.html" %}
{% block hello %}
    {% import "fenye.html" as macros %}
    <div class="tpl-content-wrapper" style="margin-top: -7px;">
        <div class="tpl-content-page-title">
        </div>
        <div class="tpl-portlet-components" style="">
            <div class="portlet-title">
                <div class="caption font-green bold">
                    <span class="am-icon-code"></span> jenkins持续集成定时任务
                </div>
            </div>
            {% with messages = get_flashed_messages() %}
                {% if messages %}
                    <ul class='flashes'>
                    {% for message in messages %}
                        <li style="color:red">{{ message }}</li>
                    {% endfor %}
                {% endif %}
            </ul>
            {% endwith %}
            <div class="tpl-block">
                <div class="am-g">
                    <div class="am-u-sm-12 am-u-md-6">
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <button class="btn btn-default">
                                    <a href="http://localhost:8080/">配置新任务</a>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <table class="am-table am-table-striped am-table-hover table-main">
                    <caption><strong>
                    </strong></caption>
                    <thead>
                    <tr>
                        <th>任务名称</th>
                        <th>jenkins地址</th>
                        <th>上次构建</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for job in jobs %}
                        <tr>
                            <td>{{ job.name }}</td>
                            <td><a href="{{ job.url }}">{{ job.url }}</a></td>
                            <td>
                                {% if job.color =='red' %}
                                    <strong style="color: red">构建失败</strong>
                                {% elif job.color=='blue' %}
                                    <strong style="color: green">构建成功 </strong>
                                {% elif job.color=='aborted' %}
                                    取消构建
                                {% else %}
                                    构建成功
                                {% endif %}
                            </td>
                            <td>
                                <span>
                                    <button class="btn btn-default">
                                        <a href="{{ url_for('home.buildjob',jobname=job.name) }}">构建</a>
                                    </button>
                                </span>
                                <button class="btn btn-default">取消构建</button>
                                <button class="btn btn-default" onclick="shourizhi('{{ job.url }}&{{ job.name }}')">
                                    构建日志
                                </button>
                                {% if current_user.role_id !=1 and current_user.role_id !=None %}
                                    <span>
                                        <button class="btn btn-default" onclick="deletemodel()">
                                            删除
                                        </button>
                                    </span>
                                {% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div style="display:none;position:fixed;z-index: 210;top: 80px;  height:70%;overflow:scroll;left: 20%;box-shadow: 0 0 10px rgba(0,0,0,0.6);border: solid 1px #255c71;border-radius: 5px 5px 0 0;background-color: antiquewhite;"
         id="shourizhi11">
        <div style="height: 5px;"><strong>jenkins后台构建日志</strong></div>
        <button class="close" onclick="closeonecase()">关闭</button>
        <div id="testresult">
        </div>
        <div style="margin-top: 5%;margin-bottom: auto">
            <input value="取消" type="button" class=" btn-default" onclick="closeonecase()">
        </div>
    </div>
{% endblock %}
{% block js %}
    <script type="text/javascript">
        function shourizhi(url) {
            var divshow = document.getElementById('shourizhi11');
            divshow.style.display = "block";
            $.ajax({
                url: '{{ url_for('home.get_jen_log') }}',
                type: 'POST',
                data: url,
                contentType: 'application/json; charset=UTF-8',
                processData: false,
                success: function (testyong) {
                    if (testyong['code'] == 200) {
                        var inte = $('#testresult');
                        inte.empty();
                        inte.append(testyong['data'])
                    }
                },
            })
        }

        function closeonecase() {
            var divshow = document.getElementById('shourizhi11');
            divshow.style.display = "none";
        }
    </script>
{% endblock %}